package com.z.common.configure.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.z.common.context.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insertFill start ...");

        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("createId", UserContext.currentUser().getId() + "", metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("updateFill start ...");

        this.setFieldValByName("updateTime", new Date(), metaObject);
        this.setFieldValByName("updateId", UserContext.currentUser().getId()+"", metaObject);
    }

}
